﻿using System.ComponentModel;
using System.Reflection;

namespace DFGK_WMS.WebAPI.Controllers
{
    public static class BaseEnum
    {
        public static List<object> GetCodeRulesList<T>()
        {
            var list = Enum.GetValues(typeof(T))
                .Cast<T>()
                .Select(item =>
                {
                    var field = typeof(T).GetField(item.ToString());
                    var description = field.GetCustomAttribute<DescriptionAttribute>();
                    return new
                    {
                        Value = item,
                        Name = item.ToString(),
                        Des = description?.Description ?? item.ToString()
                    };
                })
                .ToList<object>();

            return list;
        }
    }
}
